package daten;

import java.util.Vector;
import java.util.Observable;

import util.ProtectedIterator;

public class ProfessorenContainer extends Observable implements Iterable<Professor>
{
  private Vector<Professor> meineProfessoren = new Vector<Professor>();
  private static ProfessorenContainer unique = null;
    
  private ProfessorenContainer()
  {  
  }
   
  public static ProfessorenContainer instance()
  {
	if (unique == null)
	{
      unique = new ProfessorenContainer();
	}
	return unique;
  }

  
  
  public boolean addProfessor (Professor p)
  {
    if (meineProfessoren.contains(p)){
		System.out.println("Professor schon vorhanden");
		return false;
    }
	meineProfessoren.addElement(p);
    setChanged();
    notifyObservers();
    return true;
  }

  public void removeProfessor(Professor p)
  {
	if (p.getSizeBetreuteDiplomarbeiten()!=0){
		System.out.println("Professor kann nicht geloescht werden");
		return;
	}

	if (meineProfessoren.removeElement(p)==true){
        setChanged();
        notifyObservers();
    }
  }
 
  public Professor getProfessor(int i) 
  {
	return meineProfessoren.elementAt(i);
  }

  public void modified() 
  {
      setChanged();
      notifyObservers();
  }

  public ProtectedIterator<Professor> iterator()
  {
	return new ProtectedIterator<Professor>(meineProfessoren.iterator());
  }
}
